Page({
  data: {
    date: '',
    time: '',
    today: ''
  },

  onLoad() {
    const today = new Date().toISOString().split('T')[0];
    this.setData({ today, date: today });
  },

  onDateChange(e) {
    this.setData({ date: e.detail.value });
  },

  onTimeChange(e) {
    this.setData({ time: e.detail.value });
  },
  
  confirmTime() {
    if (!this.data.date || !this.data.time) {
      wx.showToast({ title: '请选择日期和时间', icon: 'none' });
      return;
    }

    const selectedTime = `${this.data.date} ${this.data.time}`;
    const pages = getCurrentPages();
    const prevPage = pages[pages.length - 2];

    if (prevPage) {
      prevPage.setData({
        selectedTime,
        displayTime: `${this.data.date} ${this.data.time}`
      });
      // prevPage.updateCountdown();
    }
    wx.navigateBack();
  }
});
